import { defineStore } from 'pinia'
import { requestTypeLabelList, requestGroupTypeLabelByPid, requestDeletePoetryLabelById, requestAddPoetryLabelByPid, requestAddNewLabelByTid, requestDeleteLabelByLid, requestDeleteTypeByTid, requestUpdateTypeByTid, requestAddType } from './manage-type-label.api'

export default defineStore('manageTypeLabel', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取标签分类信息
        getTypeLabelList() {
            return new Promise((resolve, reject) => {
                requestTypeLabelList().then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 获取根据诗歌id进行分组的分类与标签
        getGroupTypeLabelByPid() {
            return new Promise((resolve, reject) => {
                requestGroupTypeLabelByPid().then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据id删除诗歌标签信息
        getDeletePoetryLabelById(data: object) {
            return new Promise((resolve, reject) => {
                requestDeletePoetryLabelById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据pid添加诗歌标签
        getAddPoetryLabelByPid(data: object) {
            return new Promise((resolve, reject) => {
                requestAddPoetryLabelByPid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据tid添加标签
        getAddNewLabelByTid(data: object) {
            return new Promise((resolve, reject) => {
                requestAddNewLabelByTid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据lid删除标签
        getDeleteLabelByLid(data: object) {
            return new Promise((resolve, reject) => {
                requestDeleteLabelByLid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据tid删除分类
        getDeleteTypeByTid(data: object) {
            return new Promise((resolve, reject) => {
                requestDeleteTypeByTid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据tid更改分类名
        getUpdateTypeByTid(data: object) {
            return new Promise((resolve, reject) => {
                requestUpdateTypeByTid(data).then(response => {
                    console.log('666666',response)
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 添加分类
        getAddType(data: object) {
            return new Promise((resolve, reject) => {
                requestAddType(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
    }
})
